package main;

import java.awt.Canvas;
import java.awt.Image;
import java.awt.image.AreaAveragingScaleFilter;
import java.awt.image.CropImageFilter;
import java.awt.image.FilteredImageSource;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

public class Pictures
{
	public static Image field;
	public static Image chest[] = loadAndCut("resources/chest.png", 6, 32);
	public static Image sword = load("/resources/sword.png", 30, 100);

	public static Image[] loadAndCut(String name, int sw, int scale)
	{
		Image buf = null;
		try
		{
			buf = ImageIO.read(new File(name));
		} catch (IOException e)
		{
		}

		Image[] res = new Image[sw];
		Canvas s = new Canvas();

		for (int q = 0; q < sw; q++)
		{
			CropImageFilter filter = new CropImageFilter(q * buf.getWidth(null)
					/ sw, 0, buf.getWidth(null) / sw, buf.getHeight(null));
			res[q] = s.createImage(new FilteredImageSource(buf.getSource(),
					filter));

			AreaAveragingScaleFilter aasf = new AreaAveragingScaleFilter(scale,
					scale);
			res[q] = s.createImage(new FilteredImageSource(res[q].getSource(),
					aasf));
		}
		return res;
	}

	public static Image load(String name, int scalew, int scaleh)
	{
		Image res = null;
		try
		{
			res = ImageIO.read(new File(name));
			Canvas s = new Canvas();
			AreaAveragingScaleFilter aasf = new AreaAveragingScaleFilter(scalew,
					scaleh);
			res = s.createImage(new FilteredImageSource(res.getSource(), aasf));
			return res;
		} catch (IOException e)
		{
		}
		return null;

	}
}